package com.xiaoma.common.utils

import android.os.SystemClock

/**
 * author: liangjingbo
 * date: 2022/7/21
 * describe:
 */
object ViewUtils {
    private var lastClickTime: Long = 0

    /**
     * 防止快速重复点击（PS: 一直点击会一直返回 true）
     *
     * @return
     */
    fun isStickFastClick(time: Long): Boolean {
        var flag = false
        val curClickTime = SystemClock.elapsedRealtime()
        val diff = curClickTime - lastClickTime
        if (diff <= time) {
            flag = true
        }
        lastClickTime = curClickTime
        return flag
    }

    fun isFastClick(time: Long): Boolean {
        var flag = true
        val curClickTime = SystemClock.elapsedRealtime()
        val diff = curClickTime - lastClickTime
        if (diff >= time) {
            flag = false
            lastClickTime = curClickTime
        }
        return flag
    }


}